﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Entities;
using Context;
namespace WCF_ListenMusic.Services.Module_Video.Public
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "VideoService" in code, svc and config file together.
    public class VideoService : IVideoService
    {
        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        public List<View_BXH_Video> getBXH_Video()
        {
            try
            {
                var q = from a in context.View_BXH_Videos
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }


        public List<Song> get10Song_bySingerid(int singerid)
        {
            try
            {
                var q = from a in context.Songs
                        where a.TypeID.Equals(2) && a.SingerID.Equals(singerid)
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }


        public List<View12_Random_Video> get12Random_Video()
        {
            try
            {
                var q = from a in context.View12_Random_Videos                        
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }


        public List<SongSinger> getVideo_byCategoryID(int categoryid, int typeid)
        {
            try
            {
                var q = from a in context.SongSingers
                        where a.CategoryID.Equals(categoryid) && a.TypeID.Equals(typeid) && a.Active.Equals(true)
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }

        public List<SongSinger> getRandom10Video_byCategoryID(int categoryid, int typeid)
        {
            try
            {
                var q = (from a in context.SongSingers
                         where a.CategoryID.Equals(categoryid) && a.TypeID.Equals(typeid) && a.Active.Equals(true)
                        orderby context.GetRandomInt()
                        select a).Take(10);
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }


        public List<SongSinger> getAllVideo_bySingerID(int singerid, int typeid)
        {
            try
            {
                var q = from a in context.SongSingers
                        where a.SingerID.Equals(singerid) && a.TypeID.Equals(typeid) && a.Active.Equals(true)
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }


        public List<SongSinger> getAllVideo_byVideoName(string videoName, int typeid)
        {
            try
            {
                var q = from a in context.SongSingers
                        where a.SongName.Trim().ToUpper().Contains(videoName.Trim().ToUpper()) && a.TypeID.Equals(typeid) && a.Active.Equals(true)
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }


        public List<SongSinger> getAllVideo_bySingerName(string singerName, int typeid)
        {
            try
            {
                var q = from a in context.SongSingers
                        where a.SingerName.Trim().ToLower().Contains(singerName.Trim().ToLower()) && a.TypeID.Equals(typeid) && a.Active.Equals(true)
                        select a;
                return q.ToList();
            }
            catch (Exception ex) { throw new FaultException(ex.Message); }
        }
    }
}
